#!/usr/bin/env python
# -*- coding:utf-8 -*-
# projectname: pythoncode
# author: lzf time:2022/7/9
# name : 回合制小游戏2.0版本
import time
import random
class Role(object):
    def __init__(self, name, Armor, blood=100):
        self.name = name
        self.Armor = Armor
        self.blood = blood
        self.room = None
    def attack(self, role):
        print("普通攻击")
        role.blood -= 5
    def defense(self, role):
        if role.blood <= 95 and role.Armor == 1:
            role.blood += 5
        elif 95 < role.blood <= 100 and role.Armor == 1:
            role.blood = 100
        else:
            pass
# 定义房间
class Room(Role):
    def __init__(self,name):
        self.name = name
        self.member = []
    def enter_room(self, role):
        if not role.room:
            if len(self.member) <2:
                print(f"{role.name}成功加入{self.name}房间")
                self.member.append(role)
                role.room = self.name
            else:
                print("该房间已满")
        else:
            print("你已经加入这个房间了")
role_dict = {}
room_dict = {}
# 英雄类别
# 无极剑圣
class JianSheng(Role):
    def Q_skill(self,role):
        print("嗜血杀戮")
        role.blood -= 15
    def W_skill(self,role):
        print("万箭齐发")
        role.blood -= 10
    def E_skill(self,role):
        print("反击风暴")
        role.blood -= 13
    def R_skill(self,role):
        print("平A大宝剑")
        role.blood -= 25

# 熔岩巨兽
class RongYan(Role):
    def Q_skill(self,role):
        print("阿木木的愤怒")
        role.blood -= 9
    def W_skill(self,role):
        print("冥想")
        if self.blood <= 85:
            self.blood += 15
        else:
            self.blood = 100
    def E_skill(self,role):
        print("尖刺防御")
        role.blood -= 10
        if self.blood <= 95:
            self.blood += 5
        else:
            self.blood = 100
    def R_skill(self,role):
        print("回旋踢")
        role.blood -= 20
class VN(Role):
    def Q_skill(self,role):
        print("闪避突袭")
        role.blood -= 10
    def W_skill(self,role):
        print("圣银弩箭")
        role.blood -= 15
    def E_skill(self,role):
        print("恶魔审判")
        role.blood -= 14
    def R_skill(self,role):
        print("终极时刻")
        role.blood -= 23
class ZeiLi(Role):
    def Q_skill(self,role):
        print("电火迸射")
        role.blood -= 9
    def W_skill(self,role):
        print("强穿激光")
        role.blood -= 16
    def E_skill(self,role):
        print("灿丽花火")
        role.blood -= 16
    def R_skill(self,role):
        print("超限爆闪")
        role.blood -= 21
class RuiWen(Role):
    def Q_skill(self,role):
        print("折翼之舞")
        role.blood -= 11
    def W_skill(self,role):
        print("镇魂怒吼")
        role.blood -= 16
    def E_skill(self,role):
        print("勇往直前")
        role.blood -= 14
    def R_skill(self,role):
        print("放逐之锋")
        role.blood -= 23
if __name__ == '__main__':
    # role_pool = {'熔岩巨兽':'熔岩巨兽','无极剑圣':'无极剑圣','兔女郎瑞文':'兔女郎瑞文','泽丽':'泽丽','薇恩':'薇恩'}
    while True:
        print("欢迎来到LOL单挑小游戏".center(50, '*'))
        print("""
        1、选择英雄
        2、创建房间
        3、加入房间
        4、战斗
        5、退出
        """)
        option = input("请输入你的选择:")
        if option.isdigit():
            if option == '1':
                print("英雄列表".center(30,'*'))
                print("1、熔岩巨兽")
                print("2、无极剑圣")
                print("3、兔女郎瑞文")
                print("4、泽丽")
                print("5、薇恩")
                print(f"您的英雄池里的英雄有:{role_dict.keys()}")
                while True:
                    name = input("请输入角色名：")
                    Armor = input("请输入你是否装备防弹衣(0/1):")
                    if name not in role_dict:
                        if name == '熔岩巨兽' and Armor == '0' or name == '熔岩巨兽' and Armor == '1':
                            role_dict[name] = RongYan(name, Armor)
                            print(f"{name}角色选择成功！")
                            break
                        elif name == '无极剑圣' and Armor == '0' or name == '无极剑圣' and Armor == '1':
                            role_dict[name] = JianSheng(name, Armor)
                            print(f"{name}角色选择成功！")
                            break
                        elif name == '兔女郎瑞文' and Armor == '0' or name == '兔女郎瑞文' and Armor == '1':
                            role_dict[name] = RuiWen(name, Armor)
                            print(f"{name}角色选择成功！")
                            break
                        elif name == '泽丽' and Armor == '0' or name == '泽丽' and Armor == '1':
                            role_dict[name] = ZeiLi(name, Armor)
                            print(f"{name}角色选择成功！")
                            break
                        elif name == '薇恩' and Armor == '0' or name == '薇恩' and Armor == '1':
                            role_dict[name] = VN(name, Armor)
                            print(f"{name}角色选择成功！")
                            break
                        elif name.lower() == 'q' or Armor.lower() == 'q':
                            break
                        else:
                            print("输入不合法")
                    else:
                        print(f"{name}英雄已经选择过啦")
            elif option == '2':
                print(f"已有的房间名{room_dict.keys()}")
                name = input("请输入房间名字:")
                if name not in room_dict:
                    room_dict[name] = Room(name)
                    print(f"{name}房间创建成功！")
                else:
                    print("该房间已存在！！")
            elif option == '3':
                if room_dict and role_dict:
                    while True:
                        print(f"目前已有的角色是{role_dict.keys()},房间是{room_dict.keys()}")
                        role_name = input("请输入你选择的英雄:")
                        room_name = input("请输入你选择的房间：")
                        if role_name in role_dict and room_name in room_dict:
                            room_dict[room_name].enter_room(role_dict[role_name])
                            choice = input("你是否要继续选择英雄?(yes or no，按q退出):")
                            if choice.lower() == 'yes':
                                continue
                            elif choice.lower() == 'no':
                                break
                            else:
                                print("输入不合法请重新输入！")
                        elif room_name.lower() == 'q' or role_name.lower() == 'q':
                            break
                        else:
                            print("输入不合法！！！")
                else:
                    print("您的英雄池还没英雄或还未创建房间呢...")
            elif option == '4':
                flag = 0
                print(f"当前房间有{room_dict.keys()}")
                if len(room_dict) == 0:
                    print("您还没创建房间呢，不能进行战斗...")
                else:
                    room_name = input("请输入要进行战斗房间的名称:")
                    if len(room_dict[room_name].member) == 2:
                        print("欢迎来到召唤师峡谷，战斗开始...".center(30, ' '))
                        num = 1
                        while True:
                            print('*' * 40)
                            print(f"<--Run{num}-->".center(40, '-'))
                            skill_one = random.randint(0, 4)
                            role_one = room_dict[room_name].member[0]
                            role_two = room_dict[room_name].member[1]
                            print(f"{role_one.name}释放技能：", end='')
                            if skill_one == 0:
                                role_one.attack(role_two)
                            elif skill_one == 1:
                                role_one.Q_skill(role_two)
                            elif skill_one == 2:
                                role_one.W_skill(role_two)
                            elif skill_one == 3:
                                role_one.E_skill(role_two)
                            else:
                                role_one.R_skill(role_two)
                            print(f"{role_one.name}'s blood:{role_one.blood}")
                            print(f"{role_two.name}'s blood:{role_two.blood}")
                            if role_one.blood <= 0 or role_two.blood <= 0:
                                winner = role_one.name if role_one.blood > 0 else role_two.name
                                print(f"恭喜{winner}在第{num}回合TKO获胜！".center(30, ' '))
                                flag = 1
                                break
                            skill_two = random.randint(0, 4)
                            print(f"{role_two.name}释放技能：", end='')
                            if skill_two == 0:
                                role_two.attack(role_one)
                            elif skill_two == 1:
                                role_two.Q_skill(role_one)
                            elif skill_two == 2:
                                role_two.W_skill(role_one)
                            elif skill_two == 3:
                                role_two.E_skill(role_one)
                            else:
                                role_two.R_skill(role_one)
                            if role_one.blood <= 0 or role_two.blood <= 0:
                                winner = role_one.name if role_one.blood > 0 else role_two.name
                                print(f"恭喜{winner}在第{num}回合TKO获胜！".center(30, ' '))
                                flag = 1
                                break
                            if flag == 1:
                                break
                            num += 1
                            print(f"{role_one.name}'s blood:{role_one.blood}")
                            print(f"{role_two.name}'s blood:{role_two.blood}")
                            time.sleep(3)
                            print("战斗将持续进行，come on，召唤师们！！".center(30, '*'))
                    else:
                        print("人数不足，无法战斗！")
                    if flag == 1:
                        flag1 = 0
                        while True:
                            option1 = input("您还想再玩一把嘛？(yes or no):")
                            if option1.lower() == 'yes':
                                break
                            elif option1.lower() == 'no':
                                flag1 = 1
                                break
                            else:
                                print("输入不合法！！")
                        if flag1 == 1:
                            break
            elif option == '5':
                break
        else:
            print("输入不合法，请重新输入！")




